﻿#include "CannibalPlant.h"
#include "../../MirEnvir/Envir.h"
#include "../../../Shared/ServerPackets.h"
#include "../../../Shared/Data/Stat.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    bool CannibalPlant::getCanAttack() const
    {
        return Visible && HarvestMonster::getCanAttack();
    }

    bool CannibalPlant::getCanMove() const
    {
        return false;
    }

    bool CannibalPlant::getBlocking() const
    {
        return Visible && HarvestMonster::getBlocking();
    }

    CannibalPlant::CannibalPlant(MonsterInfo *info) : HarvestMonster(info)
    {
        Visible = false;
    }

    void CannibalPlant::ProcessAI()
    {
        if (!Dead && getEnvir()->getTime() > VisibleTime)
        {
            VisibleTime = getEnvir()->getTime() + 2000;

            bool visible = FindNearby(3);

            if (!Visible && visible)
            {
                Visible = true;
                CellTime = getEnvir()->getTime() + 500;
                Broadcast(GetInfo());
                S::ObjectShow *tempVar = new S::ObjectShow();
                tempVar->ObjectID = ObjectID;
                Broadcast(tempVar);
                ActionTime = getEnvir()->getTime() + 1000;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            }

            if (Visible && !visible)
            {
                Visible = false;
                VisibleTime = getEnvir()->getTime() + 3000;

                S::ObjectHide *tempVar2 = new S::ObjectHide();
                tempVar2->ObjectID = ObjectID;
                Broadcast(tempVar2);

                SetHP(Stats[Stat::HP]);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar2' statement was not added since tempVar2 was passed to a method or constructor. Handle memory management manually.
            }
        }

        HarvestMonster::ProcessAI();
    }

    void CannibalPlant::Turn(MirDirection dir)
    {
    }

    bool CannibalPlant::Walk(MirDirection dir)
    {
        return false;
    }

    bool CannibalPlant::IsAttackTarget(MonsterObject *attacker)
    {
        return Visible && HarvestMonster::IsAttackTarget(attacker);
    }

    bool CannibalPlant::IsAttackTarget(PlayerObject *attacker)
    {
        return Visible && HarvestMonster::IsAttackTarget(attacker);
    }

    void CannibalPlant::ProcessRoam()
    {
    }

    void CannibalPlant::ProcessSearch()
    {
        if (Visible)
        {
            HarvestMonster::ProcessSearch();
        }
    }

    Packet *CannibalPlant::GetInfo()
    {
        if (!Visible)
        {
            return nullptr;
        }

        return HarvestMonster::GetInfo();
    }
}
